/*
    Copyright (C) 2009  Twinator S.A.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.twnavigator.design
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.geom.ColorTransform;
    
    import mx.skins.ProgrammaticSkin;
	
	public class TwBackground extends ProgrammaticSkin
	{
        [Embed( source="assets/images/woodrepeat.jpg")]
        private var backgroundImageClass:Class;
        [Embed( source="assets/images/woodrepeatx.jpg")]
        private var backgroundImageClassTitle:Class;
        private var backgroundBitmapData:BitmapData;
        private var backgroundBitmapTitleData:BitmapData;
        private var tileWidth    :int;
        private var tileHeight    :int;
        private var tileWidthTitle    :int;
        private var tileHeightTitle    :int;
/**
 *  Constructor     
 */
		public function TwBackground()
        {
            super();             
/*
 * we need to get the bitmap data of our image
 */     
             var backgroundImage:Bitmap = new backgroundImageClass();
             var backgroundImageTitle:Bitmap = new backgroundImageClassTitle()
/*
 * we need to store the widthe and height - if we are to repeat on ly on once axis
 */             
             tileWidth    = backgroundImage.width;
             tileHeight    = backgroundImage.height;
             tileWidthTitle = backgroundImageTitle.width;
             tileHeightTitle = backgroundImageTitle.height;
             backgroundBitmapData = new BitmapData(tileWidth, tileHeight);
             backgroundBitmapData.draw( backgroundImage );
             backgroundBitmapTitleData = new BitmapData(tileWidthTitle, tileHeightTitle);
             backgroundBitmapTitleData.draw( backgroundImageTitle );
        }
/**
 *  @private
 */    
        override protected function updateDisplayList(    w:Number,
                                                        h:Number ):void
        {
            super.updateDisplayList( w, h );
            graphics.clear();
            graphics.beginBitmapFill( backgroundBitmapData );
            graphics.drawRect( 0, 0, w, h );            // repeat x and y
            graphics.endFill();
            graphics.beginBitmapFill( backgroundBitmapTitleData );
            //graphics.drawRect( 0, 0, tileWidth, h );    // repeat-y
            graphics.drawRect( 0, 0, w, tileHeightTitle );    // repeat-x
        }
	}
}